/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utn.tsb.tej.world_logic;

import csm.uttils.generics.Roster;

/**
 *
 * @author Administrador
 */
public class Round implements Comparable {

    private Roster<Player> turns;
    private Player point;
    private Situation situation;
    private int order;
    private static int orderCount = 0;
    boolean ended;

    public boolean isEnded() {
        return ended;
    }

    public Round(Roster<Player> turns, Situation situation) {
        this.turns = turns;
        this.situation = situation;
        orderCount++;
        order = orderCount;
        point = null;
        ended = false;
    }

    public Round(Roster<Player> turns) {
        this.turns = turns;
        orderCount++;
        order = orderCount;
        point = null;
        this.situation=new SituationClassic("nula", "nula");

    }

    public Round() {
        turns = new Roster<Player>();
        orderCount++;
        order = orderCount;
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public Situation getSituation() {
        return situation;
    }

    public void setSituation(Situation situation) {
        this.situation = situation;
    }

    public Roster<Player> getTurns() {
        return turns;
    }

    public Roster<Player> getTurnsCopy() {
        Roster<Player> turnsCopy = new Roster<Player>();
        for (int i = 0; i < turns.count(); i++) {
            turnsCopy.addLast(turns.getElementInPosition(i));
        }
        return turnsCopy;
    }

    public void setTurns(Roster turns) {
        this.turns = turns;
    }

    /**
     * this method returns the next player in the round. If ther's no more players
     * int this round it returns null. The returned player is assigned to the point
     * atributte.
     * @return next layer or null.
     */
    public Player getNextPlayer() {
        
        if (ended) {
            point = null;
        } else {
            if (point == null) {
                point = turns.getFirst();
            } else {
                int newPointIndex = turns.indexOf(point) + 1;
                if (newPointIndex == turns.count()) {
                    ended = true;
                }
                point = turns.getElementInPosition(newPointIndex);
            }
        }
        if(point!=null)        point.setConquered(false);
        return point;
    }

    @Override
    public int compareTo(Object o) {
        Round r = (Round) o;
        int dif = this.order - r.getOrder();
        return dif;
    }

    private boolean objectivesCheck() {
        return false;
    }//TODO
}
